const express = require('express');
const router = express.Router();
const pool = require('../dao/pool');
const md5 = require('md5-nodejs');

// 登录接口，成功返回用户名和id，失败返回0，需要传值（user，password）
router.post('/login',(req,res)=>{
    let sql = `select username,id from user where (email='${req.body.user}' or username='${req.body.user}') and password='${md5(req.body.password)}'`
    pool.query(sql,(err,result)=>{
        if(err) throw err;
        if(result.length != 0 ){
            res.send(result[0])
        }else{
            res.send('0')
        }
    })
})

module.exports = router;